package net.aaa.hotel.dao.impl;

import net.aaa.hotel.dao.DeptDao;
import net.aaa.hotel.entity.Dept;
import net.aaa.hotel.util.BaseDB;
import org.springframework.stereotype.Repository;

import java.util.List;
import java.util.Map;
@Repository
public class DeptDaoImpl implements DeptDao {

    @Override
    public List<Map> findAll() {
        String sql = "select * from t_dept";
        return BaseDB.queryMap(sql);
    }

    @Override
    public int addDept(Dept dept) {
        if (dept.getId() == null) {
            String sql = "insert into t_dept (name) values(?)";
            return BaseDB.update(sql,dept.getName());
        }else {
            String sql = "update t_dept set name=? where id=?";
            return BaseDB.update(sql,dept.getName(),dept.getId());
        }

    }

    @Override
    public int delDept(String gid) {
        String sql = "delete from t_dept where id=?";
        return BaseDB.update(sql,gid);
    }
}
